<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$id=$_RQ['id'];
	$item=$this->pdo_get('task_record',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$task=$this->pdo_get('task_list',array('id'=>$item['taskid'],'uniacid'=>$_SESSION['uniacid']));
	$item['type']=$task['type'];
	$item['vote_oid']=$task['vote_oid'];
	$item['content']=$task['content'];
	$status1=$this->pdo_count('task_record_log',array('status'=>1,'record_id'=>$id,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');
	$status0=$this->pdo_count('task_record_log',array('status'=>0,'record_id'=>$id,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');
	$status2=$this->pdo_count('task_record_log',array('status'=>2,'record_id'=>$id,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');
	$return['canadd']=true;
	if($status0+$status1>=$task['demand']){
		$return['canadd']=false;
	}
	$return['status0']=$status0;
	$return['status1']=$status1;
	$return['status2']=$status2;
	$return['isadd']=$status0+$status1+$status2;
	$return['lastadd']=$task['demand']-$status0+$status1;
	$return['item']=$item;
	$return['post']=array('type'=>$item['type'],'record_id'=>$id);
	set_html('title','在线打卡');
	exi($return);
}
if($_RQ['op']=='submit'){
	$postdata=get_postdata();
	if($postdata['type']==0 && !$postdata['images']){
		exi('请先上传照片！','error');
	}
	$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'lat_lng'=>ijson_encode($postdata['lat_lng']),
			'images'=>ijson_encode($postdata['images']),
			'record_id'=>intval($postdata['record_id']),
			'status'=>0,
			'type'=>$postdata['type'],
			'intime'=>TIMESTAMP,
	);
	$this->pdo_insert('task_record_log',$insert);
	exi('打卡成功！等待审核！','','/mine/');
}
?>